<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">

<!--公司跟操作区域-->
        <tree-tooles :tree-node="company" :is-root="true" @addDepts="addDepts"></tree-tooles>

<!--        树形区域-->
        <el-tree :data="departs" :props="defaultProps" :default-expand-all="true">
          <tree-tooles
            slot-scope="{data}"
            :tree-node="data"
            @del_scussess="getDpartmentInfo"
            @addDepts="addDepts"
            @editDepts="editDepts"
            >
          </tree-tooles>


        </el-tree>
      </el-card>

    </div>
    <add-dept ref="addDept" :showDialog.sync="showlog" :treeNode="node" @addOk="getDpartmentInfo"></add-dept>
  </div>
</template>

<script>
import treeTooles from './components/tress_tools'
import AddDept from './components/add-dept' // 引入新增部门组件
import {getDpartments} from "@/api/departments";
import {tranListToTreeData} from "@/utils";

export default {
  components:{
    treeTooles,
    AddDept

  },


data(){


  return{
    departs: [{ name: '总裁办', manager: '曹操', children: [{ name: '董事会', manager: '曹丕' }] },
      { name: '行政部', manager: '刘备' },
      { name: '人事部', manager: '孙权' }], //静态测试数据
    defaultProps: {
      label: 'name',
      children: 'children'
    },
    company: { name: 'xxxxx股份有限公司', manager: '负责人',  },
    showlog:false, //显示弹窗
    node:null,   //记录添加的节点
  };
  },
  created(){
    this.getDpartmentInfo()
  },
  methods:{
    //获取组织架构信息
    async getDpartmentInfo(){
    const resoult = await getDpartments()
    this.company={name:'xxxxx股份有限公司',manager: '负责人',id:''}
    this.departs=tranListToTreeData(resoult.depts,'')
    },

    //监听子组件添加时响应的方法（添加部门）
    addDepts(node){
      this.showlog=true
      this.node=node
    },
//编辑
    editDepts(node){
      this.showlog=true
      this.node=node
      this.$refs.addDept.getDepartDetail(node.id)



    }
  }

}
</script>

<style lang="scss" scoped>
//下拉菜单
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF
}
.el-icon-arrow-down {
  font-size: 12px
}
//树形卡片
.tree-card {
  padding: 30px  140px;
  font-size:14px;
}
</style>
